<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <!-- Online install -->
    <link rel="stylesheet" type="text/css" href="//code.jquery.com/qunit/qunit-1.18.0.css" />
    <!-- Local install for Travis-CI -->
    <link rel="stylesheet" type="text/css" href="../../../qunit/qunit-1.18.0.css" />

    <!-- Add www/tests (i.e. parent) folder to PYTHONPATH -->
    <link rel="pythonpath" href=".." hreflang="py" />

    <!-- Needed in sys.path init tests , see test_import.py -->
    <link id="link_none1" rel="pythonpath" href="/nowhere1" hreflang="none" />
    <link id="link_none2" rel="pythonpath" href="/nowhere2" hreflang="x-none" />
    <link id="link_empty_vfs" rel="pythonpath prefetch" href="../test.empty.vfs.js" />
  </head>
  <body onload="brython({debug:1, cache:'none', static_stdlib_import:true})">
    <!-- QUnit init -->
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>
    <!-- Online install -->
    <script src="//code.jquery.com/qunit/qunit-1.18.0.js"></script>
    <!-- Local install for Travis-CI -->
    <script src="../../../qunit/qunit-1.18.0.js"></script>

    <!-- Testem integration -->
    <script src="/testem.js"></script>

    <!-- Brython init -->
    <script type="text/javascript" src="../../src/unicode.min.js"></script>

    <script type="text/javascript" src="../../src/brython_builtins.js"></script>
    <script type="text/javascript" src="../../src/version_info.js"></script>
    <script type="text/javascript" src="../../src/py2js.js"></script>
    <script type="text/javascript" src="../../src/loaders.js"></script>
    <script type="text/javascript" src="../../src/py_object.js"></script>
    <script type="text/javascript" src="../../src/py_type.js"></script>
    <script type="text/javascript" src="../../src/py_utils.js"></script>
    <script type="text/javascript" src="../../src/py_sort.js"></script>
    <script type="text/javascript" src="../../src/py_builtin_functions.js"></script>
    <script type="text/javascript" src="../../src/py_exceptions.js"></script>
    <script type="text/javascript" src="../../src/py_range_slice.js"></script>
    <script type="text/javascript" src="../../src/py_bytes.js"></script>
    <script type="text/javascript" src="../../src/py_set.js"></script>
    <script type="text/javascript" src="../../src/js_objects.js"></script>
    <script type="text/javascript" src="../../src/stdlib_paths.js"></script>
    <script type="text/javascript" src="../../src/py_import.js"></script>

    <script type="text/javascript" src="../../src/py_string.js"></script>
    <script type="text/javascript" src="../../src/py_int.js"></script>
    <script type="text/javascript" src="../../src/py_long_int.js"></script>
    <script type="text/javascript" src="../../src/py_float.js"></script>
    <script type="text/javascript" src="../../src/py_complex.js"></script>
    <script type="text/javascript" src="../../src/py_dict.js"></script>
    <script type="text/javascript" src="../../src/py_list.js"></script>
    <script type="text/javascript" src="../../src/py_generator.js"></script>
    <script type="text/javascript" src="../../src/py_dom.js"></script>

    <script type="text/javascript" src="../../src/builtin_modules.js"></script>
    <script type="text/javascript" src="../../src/py_import_hooks.js"></script>
    <script type="text/javascript" src="../../src/async.js"></script>

    <!-- Javascript code needed to run tests included in dom.py -->
    <script type="text/javascript" src="../dom_js_tests.js"></script>
    <!-- HTML needed to run tests included in dom.py -->
    <div id="dom-test-element-id"></div>

    <!-- Javascript code needed to run JSObject tests -->
    <script type="text/javascript" src="../jsobj_tests.js"></script>

    <script type="text/javascript" src="/src/brython_stdlib.js"></script>

<script type="text/python3">
from javascript import JSObject
from browser import window
import brython_test_utils as utils
from   brython_test_utils import unittest as test_utils
import unittest
import traceback

def testTraceback(qunit):
    """ Traceback tests for source code printing """
    # issue 859
    def f():
        return 1 / 0

    try:
        f()
    except Exception:
        exception_info = traceback.format_exc()
        assert 'f()' in exception_info
        assert '1 / 0' in exception_info
        assert ', in f' in exception_info

    # issue 885
    try:
        1/0
    except:
        assert '1/0' in traceback.format_exc()

    # issue 887
    try:
        exec('def f(): return 1/0\nf()')
    except ZeroDivisionError:
        traceback.print_exc()
        trace = traceback.format_exc()
        assert 'exec(\'def f(): return 1/0\\nf()\')' in trace
        assert 'f()' in trace
        assert 'def f(): return 1/0\\n' in trace

    # issue 961
    from z import f

    try:
        f()
    except ZeroDivisionError:
        trace = traceback.format_exc()
        assert "line 9, in f" in trace
        assert "line 6, in h" in trace
        assert "line 5, in <lambda>" in trace
        assert "line 2, in g" in trace

    # issue 976
    try:
        exec("""t = (
                     1, 2, 3,
                     4, 5 6
                )""")
        raise Exception("should have raised SyntaxError")
    except SyntaxError as exc:
        assert exc.lineno == 3

    qunit.ok(True)

_QUnit = window.QUnit
_QUnit.test('testTraceback', testTraceback)

# TODO: Arg values e.g. verbosity level ?
result = test_utils.OneTimeTestResult()

def qunit_add_tests(suite):
    module_name = getattr(suite, 'caption', None) or 'All tests'
    _QUnit.module(module_name)
    pend = []
    for test in suite:
        if isinstance(test, unittest.BaseTestSuite):
            pend.append(test)
        else:
            testName = test.shortDescription() or test.id()
            _QUnit.test(testName, test_utils.qunit_test(testName, test, result))
    for suite in pend:
        qunit_add_tests(suite)

qunit_add_tests(test_utils.load_brython_test_cases('..'))

from unittest.loader import TestLoader
import test.test_dict
import test.test_grammar
qunit_add_tests(TestLoader().loadTestsFromModule(test.test_dict))
qunit_add_tests(TestLoader().loadTestsFromModule(test.test_grammar))

</script>

  </body>
</html>

